﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;

namespace BanSach
{
    public partial class frmQLSach : Form
    {
        public frmQLSach()
        {
            InitializeComponent();
        }
        int typeSeach;
        private void button3_Click(object sender, EventArgs e)
        {
            dataGridView1.DataSource = TheLoai_BUS.Load();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            dataGridView1.DataSource = Sach_BUS.LoadSach();
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                typeSeach = 1;
            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton2.Checked)
            {
                typeSeach = 2;
            }
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton3.Checked)
            {
                typeSeach = 3;
            }
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton4.Checked)
            {
                typeSeach = 4;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            switch (typeSeach)
            {
                case 1:
                    {
                        dataGridView1.DataSource = Sach_BUS.TimTenSach(textBox1.Text);
                        break;   
                    }
                case 2:
                    {
                        dataGridView1.DataSource = Sach_BUS.TimMaSach(textBox1.Text);
                        break;
                    }
                case 3:
                    {
                        dataGridView1.DataSource = Sach_BUS.TimTheLoai(textBox1.Text);
                        break;
                    }
                default:
                    {
                         dataGridView1.DataSource = Sach_BUS.TimNXB(textBox1.Text);
                        break;
                    }
            }
        }

        private void btnHienThi_Click(object sender, EventArgs e)
        {
            dataGridView2.DataSource = Sach_BUS.LoadSach();
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            Sach_BUS.XoaSach(textBox2.Text);
            dataGridView2.DataSource = Sach_BUS.LoadSach();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            dataGridView3.DataSource = Sach_BUS.LoadSach();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string masach = textBox3.Text;
            string tensach = textBox4.Text;
            string maloaisach = textBox5.Text;
            string maNXB = textBox6.Text;
            float gianhap = float.Parse(textBox7.Text);
            float giaxuat = float.Parse(textBox8.Text);
            int soluongco = int.Parse(textBox9.Text);
            Sach_DTO sach = new Sach_DTO(masach, tensach, maloaisach, maNXB, gianhap, giaxuat, soluongco);
            Sach_BUS.ThemSachMoi(sach);
            dataGridView3.DataSource = Sach_BUS.LoadSach();

        }

        private void button7_Click(object sender, EventArgs e)
        {
            dataGridView4.DataSource = TheLoai_BUS.Load();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            string maloai = textBox10.Text;
            string tenloai = textBox11.Text;
            LoaiSach_DTO loaisach = new LoaiSach_DTO(maloai, tenloai);
            TheLoai_BUS.ThemTL(loaisach);
            dataGridView4.DataSource = TheLoai_BUS.Load();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            dataGridView5.DataSource = Sach_BUS.LoadSach();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            string masach = textBox18.Text;
            string tensach = textBox17.Text;
            string maloaisach = textBox16.Text;
            string maNXB = textBox15.Text;
            float gianhap = float.Parse(textBox14.Text);
            float giaxuat = float.Parse(textBox13.Text);
            int soluongco = int.Parse(textBox12.Text);
            Sach_DTO sach = new Sach_DTO(masach, tensach, maloaisach, maNXB, gianhap, giaxuat, soluongco);
            Sach_BUS.SuaSach(sach);
            dataGridView5.DataSource = Sach_BUS.LoadSach();
        }

    }
}
